package com.nsgf.library.widget.prckerview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {

    private SurfaceHolder holder;
    private OnSurfaceCreatedListener listener;

    public CustomSurfaceView(Context context) {
        super(context);
        init();
    }

    public CustomSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomSurfaceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        holder = getHolder();
        holder.addCallback(this);
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        if (listener != null) {
            listener.onSurfaceCreated();
        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        // Handle surface changed
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        if (listener != null) {
            listener.onSurfaceDestroyed();
        }
    }

    public void setOnSurfaceCreatedListener(OnSurfaceCreatedListener listener) {
        this.listener = listener;
    }

    public interface OnSurfaceCreatedListener {
        void onSurfaceCreated();
        void onSurfaceDestroyed();
    }
}
